package main

import (
	"gin/controller"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

// air: 热加载, 开发工具 go get -u github.com/cosmtrek/air
func main() {

	r := gin.Default()

	// 1.渲染HTML模板 - 不常用
	//r.LoadHTMLGlob("/templates/**/*")
	// 静态资源文件
	// r.Static()
	//r.LoadHTMLFiles("templates/posts/index.html",
	//	"templates/users/index.html")
	//
	//r.GET("/posts/index", func(c *gin.Context) {
	//	c.HTML(http.StatusOK, "templates/posts/index.html", gin.H{
	//		"title": "posts/index.html",
	//	})
	//})
	//
	//r.GET("/users/index", func(c *gin.Context) {
	//	c.HTML(http.StatusOK, "templates/users/index.html", gin.H{
	//		"title": "users/index.html",
	//	})
	//})

	// 2. 渲染json, xml, yaml, protobuf - gin 自动处理
	// c.XXX 格式
	r.GET("/hello", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": http.StatusText(http.StatusOK),
		})
	})

	// rest
	controller.RegisterRoutes(r)
	controller.ParseQueryParams(r)

	log.Fatalln(r.Run(":80"))

}
